<?php

namespace app\index\controller;

use think\Controller;
use think\Db;

// 前台基类
class Base extends Controller
{

    // 首页数据
    public function getHome()
    {
    }

    // 轮播数据
    public static function getBanner()
    {
        // 设置别名
        $sqlfield = 'banner_id as vod_id,banner_title as vod_title,banner_pic as vod_pic,banner_url as vod_url,banner_sort as vod_sort,banner_type as vod_type,banner_click as vod_click,banner_close as vod_close,DATE_FORMAT(banner_time, "%Y-%m-%d %H:%s") as vod_time';
        //    获取数据
        $banner = db('v1_banner')->where("banner_close", "on")->field($sqlfield)->select();
        return $banner;
    }

    // 广告数据
    public static function getAdData($_column = '')
    {
        // 是否全局
        if (empty($_column)) {
            $column = ['all'];
        } else {
            $column = ['all', $_column];
        }
        $field = "ad_id AS 'id',ad_title AS 'title',ad_content AS 'content',ad_column AS 'column',ad_sort AS 'sort',ad_fixed AS 'fixed',ad_time AS 'time'";
        // 查询广告内容
        $ad = db('v1_ad')->where('ad_state', 'on');
        $ads = $ad->whereIn('ad_column', $column)->field($field)->select();
        return $ads;
    }

    // 视频观看记录 
    public static function getPlays()
    {
        $field = 'see_id as id,see_title as title,see_pic as pic,see_url as url,see_type as type,see_count as count,DATE_FORMAT(see_time, "%Y-%m-%d %H:%s") as time';
        $data = db('v1_see_record')->where('user_id', session('userinfo')['user_id'])->field($field)->select();
        return $data;
    }

    public function getReq($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        $img = curl_exec($ch);
        return $img;
    }
}
